package com.gupaoedu.xin.vip.pattern.factory.simplefactory;

import com.gupaoedu.xin.vip.pattern.factory.ICourse;
import com.gupaoedu.xin.vip.pattern.factory.JavaCourse;
import com.gupaoedu.xin.vip.pattern.factory.PythonCourse;

import javax.sound.midi.Soundbank;

public class SimpleFactory {

    public ICourse create(String name){
        if (name=="java"){
            return new JavaCourse();
        }else if (name == "python"){
            return new PythonCourse();
        }
        return null;
    }

    /**
     * 路径+类名
     * @param clazzname
     * @return
     */
    public ICourse create(String url,String clazzname){
        if (null==url && null==clazzname){
            return null;
        }
        String classname = url+clazzname;
        try {
            return (ICourse) Class.forName(classname).newInstance();

        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public ICourse create(Class<? extends ICourse> clazz){

        try {
            return clazz.newInstance();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

}
